class EpisodeDataParseError <  RuntimeError
end

#parsed data from the r
class EpisodeDataParser
  attr_reader :season, :episode, :torrent_group, :pub_date, :title
  
  def initialize(rss_item)
    @rss_item = rss_item
    @season = nil
    @episode = nil
    @torrent_group = nil
    @pub_date = nil
    @title = nil
    @valid = true
    @errors = []
    
    parse
    
    return self
  end
  
  def valid?
    return @valid
  end
  
  def parse
    parse_season_and_episode
    parse_torrent_group
    parse_pub_date
    parse_title
  end
  
  private
  
  def parse_season_and_episode
    @rss_item[:title] =~/\ (\d+)x(\d+)\ /
    @season = $1.to_i unless $1.nil?
    @episode = $2.to_i unless $2.nil?
    
    # if(@season.nil? || @episode.nil?)
    #   raise EpisodeDataParseError, "Could not parse season and episode"
    # end  
  end
  
  def parse_torrent_group
    @rss_item[:title] =~ /\[(.*)\]/
    @torrent_group = $1
  end
  
  def parse_pub_date
    @pub_date = @rss_item[:pubDate]
  end
  
  def parse_title
  end
end